package com.warning_speed_android.gps;

import android.content.Context;
import android.location.Location;
import android.util.Log;
import android.widget.Toast;
import com.warning_speed_android.socket.CustomClient;
import com.warning_speed_android.worker.BaseWorker;

public class AutoSendLocation extends BaseWorker {
	GPSTracker gps;
	private final Context context;

	public AutoSendLocation(Context context) {
		gps = new GPSTracker(context);
		this.context = context;
	}

	@Override
	protected void onProcess() {
		Location location  = gps.getLocation();
		if (gps.isCanGetLocation()) {
			if(location != null){
				try {
					CustomClient.instance.sendLocation(String.valueOf(location.getLatitude()), String.valueOf(location.getLongitude()));
					Toast.makeText(context,
							"Your location is \nLat: " + location.getLatitude() + "\nLon: " + location.getLongitude(),
							Toast.LENGTH_LONG).show();
				} catch (Exception e) {
					// TODO: handle exception
					Log.e(AutoSendLocation.class.getSimpleName(), e.getMessage(), e);
				}
			}
		}else{
			gps.showSettingAlert();
		}
		
		
		

	}
}
